import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  Platform,
  Picker,
} from 'react-native';

import Config from '../../config';
import Colors from '../../common/Colors';
import CommonStyles from '../../common/CommonStyles';
import SizeUtils from '../../common/SizeUtils';
import TImage from '../../components/TImage';
import WH_Constants from './WH_Constants';
import CommonListPage from '../common/CommonListPage';
import {DateUtils} from '../../utils/Utils';
import WH_PostItemView from './WH_PostJDZItemView';
import CommonShowPickerAction from '../../actions/common/CommonShowPickerAction';
import WH_RequestDepartmentAction from '../../actions/workhard/WH_RequestDepartmentAction';
import WH_RequestVotecAction from '../../actions/workhard/WH_RequestVotecAction';


const SORT_ARR=[
  {key:'1',name:'回复'},
  {key:'2',name:'评审'},
];
const SUB_ARR1=[
  {key:'1',name:'未回复'},
  {key:'2',name:'已回复'},
  {key:'3',name:'未推荐'},
  {key:'4',name:'已推荐'},
  {key:'5',name:'全部'},
];
const SUB_ARR2=[
  {key:'1',name:'月待评'},
  {key:'2',name:'年度待评'},
  {key:'3',name:'已评'},
  {key:'4',name:'全部'},
];

export default class WH_ZhuanjiaPage extends CommonListPage {
  constructor(props) {
    super(props);
    this.select_index=0; 
    this.select_sub=0;
    this._dataKey = "postzhuan_id";
  }
	_getViewStyle() {
      return {paddingTop:Config.paddingTop,
        backgroundColor:"#ffffff"}
  	}
	_getListViewStyle() {
      return {
        width:SizeUtils.getWindowSize().width,
        paddingTop:0,
        height:(SizeUtils.getWindowSize().height - Config.paddingTop - SizeUtils.translateDesignHeightToCode(0)),
        backgroundColor:"#fff"};
  	}
    refRefresh(){
      this.doRefresh();
    }
  	_onRenderItem(data, index) {
      var isPing = false;
      var pingType=0;
      if (this.select_index==1) {
        isPing=true;
      }
      if (this.select_sub==0) {
        pingType=1;
      }
      if (this.select_sub==1) {
        pingType=2;
      }
    	return (<WH_PostItemView data={data} refRefresh={this.refRefresh.bind(this)} index={index} showNum = {true} pingType={pingType} isZhuanjia={true} isPing={isPing} />)
  	}
    _onRenderHeader(){
    if (this._listView) {
      const arr = this.select_index===0?SUB_ARR1:SUB_ARR2;
    	return(
      		<View>
            <View style={{
              flexDirection:"row",
              borderColor:'#eeeeee',
              borderBottomWidth:SizeUtils.translateDesignHeightToCode(3),
              height:SizeUtils.translateDesignHeightToCode(80),
              justifyContent:"space-around",
            }}>
              {SORT_ARR.map((item,index)=> this._getSortButton(item,index) )}
            </View>
            <View style={{
              height:SizeUtils.translateDesignHeightToCode(20),
              backgroundColor:'#eee'}}/>

            <View style={{
              flexDirection:"row",
              borderColor:'#eeeeee',
              borderBottomWidth:SizeUtils.translateDesignHeightToCode(3),
              height:SizeUtils.translateDesignHeightToCode(80),
              justifyContent:"space-around",
            }}>
              {arr.map((item,index)=> this._getSortButton1(item,index) )}
            </View>
            <View style={{
              height:SizeUtils.translateDesignHeightToCode(20),
              backgroundColor:'#eee'}}/>
          </View>
    	);
      }
  	}
 	 _requestData(page, listView) {
    const select_index= this.select_index;
    const select_sub= this.select_sub;
    if (select_index===1) {
      new WH_RequestVotecAction().call(listView, {type:SUB_ARR2[select_sub].key,
      page:page, page_size:10});
    }else{
      let officialStr ;
      let recommendStr ;
      if (select_sub===0) {
        officialStr=0;
      }else if (select_sub===1) {
        officialStr=1;
      }else if (select_sub===2) {
        recommendStr=0;
      }else if (select_sub===3) {
        recommendStr=1;
      }
      new WH_RequestDepartmentAction().call(listView, {official :officialStr,recommend:recommendStr,
      page:page, page_size:10});
    }
	}
  _getSortButton(typeData,index) {
    return (
      <TouchableOpacity
        key={typeData.key}
        onPress = {() => {
          if (this.select_index!==index) {
            this.select_index=index;
            this.select_sub=0;
            this.doRefresh();
          }
        }}
        style={[{
          borderColor:'#eeeeee',
          flex:1,
          alignItems: 'center',
          justifyContent: 'center',
          borderRightWidth:SizeUtils.translateDesignWidthToCode(3)
        }]}>
          <Text style={[CommonStyles.secondaryText,
              {textAlign:"center",color:index===this.select_index?'#ee3535':'#000',
              fontSize:SizeUtils.translateFontSizeToCode(30),
              backgroundColor:"#00000000", borderWidth:0,}]}>{typeData.name}
          </Text>
      </TouchableOpacity>
    )
  }
  _getSortButton1(typeData,index) {
    return (
      <TouchableOpacity
        key={typeData.key}
        onPress = {() => {
          if (this.select_sub!==index) {
            this.select_sub=index;
            this.doRefresh();
          }
        }}
        style={[{
          borderColor:'#eeeeee',
          flex:1,
          alignItems: 'center',
          justifyContent: 'center',
          borderRightWidth:SizeUtils.translateDesignWidthToCode(3)
        }]}>
          <Text style={[CommonStyles.secondaryText,
              {textAlign:"center",color:index===this.select_sub?'#ee3535':'#000',
              fontSize:SizeUtils.translateFontSizeToCode(30),
              backgroundColor:"#00000000", borderWidth:0,}]}>{typeData.name}
          </Text>
      </TouchableOpacity>
    )
  }
}